from email.policy import default
from ..extensions import db
from datetime import datetime

class UserInfo(db.Model):
    # 用户信息
    __tablename__ = "user_info"
    id            = db.Column(db.Integer, primary_key=True)
    username      = db.Column(db.String(50), unique=True, index=True)
    password      = db.Column(db.String(50), default='123456')
    timestamp     = db.Column(db.DateTime, default=datetime.utcnow)
    lastLogin     = db.Column(db.DateTime, default=datetime.utcnow)
    lastLogout    = db.Column(db.DateTime, default=datetime.utcnow)

    def get_info(self):
        data = {'id': self.id, 'username': self.username, 'password': self.password, }
        return data

class UserLogInfo(db.Model):
    # 用户登录信息
    __tablename__ = "user_log_info"
    id            = db.Column(db.Integer, primary_key=True)
    username      = db.Column(db.String(50), index=True)
    lastLogin     = db.Column(db.DateTime, default=datetime.utcnow)
    lastLogout    = db.Column(db.DateTime, default=datetime.utcnow)

    def get_info(self):
        data = {'id': self.id, 'username': self.username, 'lastLogin': self.lastLogin, 'lastLogout': self.lastLogout}
        return data

class UserOperationInfo(db.Model):
    # 用户操作信息
    __tablename__ = "user_operation_info"
    id            = db.Column(db.Integer, primary_key=True)
    username      = db.Column(db.String(50), index=True)
    operation     = db.Column(db.String(50), default='None')
    
    def get_info(self):
        data = {'id': self.id, 'username': self.username, 'operation': self.operation,}
        return data
